from rest_framework.generics import ListCreateAPIView
from users.models import User
from meiduo_admin.utils import PageNum
from meiduo_admin.serializers.users import UserSerializer


class UserView(ListCreateAPIView):
    serializer_class = UserSerializer
    pagination_class = PageNum

    def get_queryset(self):
        if self.request.query_params.get("keyword") == "" or self.request.query_params.get("keyword") is None:
            return User.objects.all()
        else:
            return User.objects.filter(username__contains=self.request.query_params.get("keyword"))
